#include<iostream>
#include<cstring>
#include<string>
using namespace std;
const int N = 1e6 + 10, P = 133, M = 1e4 + 10;
int s1[M], s2[N], p[N];
int main()
{
	int t = 0;
	cin >> t;
	while (t--) {
		string a, b;
		cin >> a >> b;
		memset(p, 0, sizeof(p));
		memset(s1, 0, sizeof(s1));
		memset(s2, 0, sizeof(s2));
		p[0] = 1;
		for (int i = 1; i <= a.size(); i++) {
			s1[i] = s1[i - 1] * P + a[i - 1] - '0';
		}
		for (int i = 1; i <= b.size(); i++) {
			s2[i] = s2[i - 1] * P + b[i - 1] - '0';
			p[i] = p[i - 1] * P;
		}
		int cnt = 0;
		int n = a.size();
		int m = b.size();
		for (int i = 1; n + i - 1 <= m; i++) {
			int r = i + n - 1;
			if (s1[n] == s2[r] - s2[i - 1] * p[r - i + 1]) {
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}
//int main()
//{
//	int t;
//	cin >> t;
//	while (t--) {
//		string a;
//		string b;
//		cin >> a >> b;
//		if (a.size() > b.size()) {
//			cout << 0 << endl;
//			continue;
//		}
//		int cnt = 0;
//		while (b.find(a) != -1) {
//			cnt++;
//			b.erase(b.find(a), 1);
//		}
//		cout << cnt << endl;
//	}
//	return 0;
//}